#include <stdio.h>
#include "log.h"
#include <stdlib.h>
#include "constant.h"
char *get_file_buff( const char *path)
{
	FILE *pfile;
	long file_len;
	int read_len;
	char *buff;
	
	LOG_DEBUG("path: %s\n", path);
	pfile = fopen(path, "rb");	
	if (!pfile) {
		LOG_ERR("fopen failed\n");
		return 0;
	}
	
	fseek(pfile, 0, SEEK_END);
	file_len = ftell(pfile);
	fseek(pfile, 0, SEEK_SET);
	
	buff = (char *)malloc(file_len + 1);
	
	read_len = (int)fread(buff , sizeof(char), file_len, pfile );
	if ( -1 == read_len) {
		LOG_ERR("fread failed\n");	
		SAFE_FREE(buff);
		fclose(pfile);
		return 0;
	}
	
	fclose(pfile);
	
	buff[file_len] = 0;
	
	return buff;
}

